package jianzhiOfferII;

import java.util.Arrays;

//剑指 Offer II 012. 左右两边子数组的和相等
public class Num012_pivotIndex {
    public int pivotIndex(int[] nums) {
        int total = Arrays.stream(nums).sum();//数组求和
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            if (sum * 2 + nums[i] == total){
                return i;
            }
            sum += nums[i];
        }
        return -1;

    }
}
